<template>
	<view class="container">
			<view class="example">
				<!-- 基础用法，不包含校验规则 -->
				<uni-forms ref="baseForm" :modelValue="baseFormData" :rules="dynamicRules">
					<uni-forms-item label="学科" required name="kcmc">
						<uni-easyinput v-model="baseFormData.kcmc" placeholder="请输入学科名称" />
					</uni-forms-item>
					<uni-forms-item label="类型" required name="kcxz">
						<uni-data-checkbox v-model="baseFormData.kcxz" :localdata="kcxz" />
					</uni-forms-item>
					<uni-forms-item label="课程老师" required name="jsxx">
						<uni-easyinput v-model="baseFormData.jsxx" placeholder="请输入课程老师名称" />
					</uni-forms-item>
					<uni-forms-item label="教室" required name="jxdd">
						<uni-easyinput v-model="baseFormData.jxdd" placeholder="请输入教室" />
					</uni-forms-item>
					<uni-forms-item label="上课星期" required name="week">
						<uni-data-select v-model="baseFormData.week" :localdata="week"></uni-data-select>
					</uni-forms-item>
					<uni-forms-item label="上课时段" required name="jc">
						<!-- <uni-data-select v-model="baseFormData.jc" :localdata="jc"></uni-data-select> -->
						<uni-data-checkbox multiple v-model="baseFormData.jc" :localdata="jc" @change="change"></uni-data-checkbox>
					</uni-forms-item>
				</uni-forms>
			</view>
			
			<button type="primary" @click="submit('baseForm')">提交</button>
		</uni-section>
	</view>
</template>

<script>
import { addCourse } from '@/api/CourseMange.js'

export default {
	data() {
		return {
			// 基础表单数据
			baseFormData: {
				courseName: '',
				courseType: 0,
				jsxx: uni.getStorageSync("loginInfo").user.userName,//课程老师
				teacherId: uni.getStorageSync("loginInfo").user.userId,//课程老师
				jxdd: "教室103",//课程教室
				week: 1,//课程上课星期，周日为0，周一为1依次顺延
				jc: [1],//第几节课
			},
			kcxz: [{
				text: '必修',
				value: 0
			}, {
				text: '选修',
				value: 1
			}],
			week: [
				{ value: 1, text: "周一" },
				{ value: 2, text: "周二" },
				{ value: 3, text: "周三" },
				{ value: 4, text: "周三" },
				{ value: 5, text: "周五" },
			],
			jc: [
				{ value: 1, text: "第一节课" },
				{ value: 2, text: "第二节课" },
				{ value: 3, text: "第三节课" },
				{ value: 4, text: "第四节课" },
				{ value: 5, text: "第五节课" },
				{ value: 6, text: "第六节课" },
				{ value: 7, text: "第七节课" },
				{ value: 8, text: "第八节课" },
			],
			dynamicRules: {
				kcmc: {
					rules: [{
						required: true,
						errorMessage: '不能为空'
					}]
				},
				kcxz: {
					rules: [{
						required: true,
						errorMessage: '不能为空'
					}]
				},
				jsxx: {
					rules: [{
						required: true,
						errorMessage: '不能为空'
					}]
				},
				jxdd: {
					rules: [{
						required: true,
						errorMessage: '不能为空'
					}]
				},
				week: {
					rules: [{
						required: true,
						errorMessage: '不能为空'
					}]
				},
				jc: {
					rules: [{
						required: true,
						errorMessage: '不能为空'
					}]
				}
			}
		}
	},
	onLoad() {
	
	},
	onShow() {

	},
	methods: {
		async submit(){
			const { data: { code, data,msg } } = await addCourse({'xcxCode':e,'code':openidCode})
		},
		change(e){
			console.log('e:',e);
			console.log(this.jc);
		}
	},
}
</script>

<style>
	.example {
		padding: 15px;
		background-color: #fff;
	}

	.segmented-control {
		margin-bottom: 15px;
	}

	.button-group {
		margin-top: 15px;
		display: flex;
		justify-content: space-around;
	}

	.form-item {
		display: flex;
		align-items: center;
	}

	.button {
		display: flex;
		align-items: center;
		height: 35px;
		margin-left: 10px;
	}
</style>